import requests

from config import appSettings


class Auth:
    def __init__(self):
        return


def wx_login(js_code: str):
    url = (
        f"https://api.weixin.qq.com/sns/jscode2session?appid={appSettings.wx_app_id}&secret={appSettings.wx_app_secret}"
        f"&js_code={js_code}&grant_type=authorization_code"
    )

    resp = requests.get(url)
    data = resp.json()
    print(data)
    if "openid" not in data:
        return data, data["errcode"]
    return data, 0
